<template>
  <div class="users_container">
    <!-- 面包屑(路径导航功能) -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <!-- 卡片 栅格系统(搜索栏)-->
      <el-row :gutter="20">
        <el-col :span="6">
          <el-input
            v-model="reqParams.query"
            placeholder="请输入内容"
            clearable
            @clear="getData()"
            @keyup.enter.native="getData()"
          >
            <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
          </el-input>
        </el-col>
        <!-- 添加用户 1-1 -->
        <el-col :span="18">
          <!-- <el-button type="primary" @click="addDialogFormVisible = true">添加用户</el-button> -->
          <el-button type="primary" @click="openAddDialog()">添加用户</el-button>
        </el-col>
      </el-row>
      <!-- 卡片 表格-->

      <el-table :data="usersList" border style="width: 100%">
        <el-table-column type="index" label="序号" width="60"></el-table-column>
        <el-table-column prop="username" label="用户名" width="180"></el-table-column>
        <el-table-column prop="mobile" label="手机号码"></el-table-column>
        <el-table-column prop="role_name" label="角色"></el-table-column>
        <el-table-column prop="email" label="邮箱"></el-table-column>
        <el-table-column prop="mg_state" label="状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.mg_state"
              active-color="#13ce66"
              inactive-color="#ff4949"
              @change="toggleState(scope.row)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <!-- <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>-->
          <template slot-scope="scope">
            <el-button-group>
              <el-button
                type="primary"
                icon="el-icon-edit"
                round
                @click="openEditDialog(scope.row)"
              ></el-button>
              <el-button type="primary" icon="el-icon-delete" @click="delUser(scope.row.id)"></el-button>
              <el-button
                type="primary"
                icon="el-icon-setting"
                round
                @click="openChangeRole(scope.row)"
              ></el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>

      <!-- 卡片 分页-->
      <div class="block">
        <el-pagination
          @size-change="size"
          @current-change="pager"
          :current-page="reqParams.pagenum"
          :page-sizes="[1, 2, 4, 8]"
          :page-size="reqParams.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
        <!-- <el-pagination
          background
          layout="prev, pager, next"
          :page-count="total"
          :current-page="reqParams.pagenum"
          @current-change="pager"
        ></el-pagination>-->
      </div>
    </el-card>
    <!-- 添加用户 1-2 -->
    <!-- <el-dialog title="添加用户" :visible.sync="addDialogFormVisible" @close="addDialogClose()"> -->
    <el-dialog title="添加用户" :visible.sync="addDialogFormVisible">
      <el-form
        :model="addForm"
        autocomplete="off"
        :rules="addRules"
        ref="addForm"
        label-width="80px"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="addForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="addForm.password"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="addForm.email"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="mobile">
          <el-input v-model="addForm.mobile"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addUser()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 分配角色 1-1 -->
    <el-dialog title="用户分配角色" :visible.sync="roleDialogFormVisible">
      <el-form :label-width="formLabelWidth">
        <el-form-item label="当前用户：">{{ roleUserName }}</el-form-item>
        <el-form-item label="当前角色：">{{ roleName }}</el-form-item>
        <el-form-item label="分配角色：">
          <el-select v-model="roleSelected" placeholder="请选择">
            <el-option
              v-for="item in roleList"
              :key="item.id"
              :label="item.roleName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="roleDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="changeRole()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 编辑用户对话框 -->
    <el-dialog title="编辑用户" :visible.sync="editDialogFormVisible">
      <el-form
        :model="editForm"
        autocomplete="off"
        :rules="editRules"
        ref="editForm"
        label-width="80px"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="editForm.username" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="editForm.email"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="mobile">
          <el-input v-model="editForm.mobile"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="editUser()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "./User-Mixin.js";
export default {
  mixins: [mixin]
};
</script>

<style lang="less" scoped></style>
